﻿using System;
using System.Globalization;
using Microsoft.Xna.Framework;

namespace XTengine.ComponentModel
{
    public class Vector2Converter : TypeConverter<Vector2>
    {
        public override Vector2 ConvertFrom(string value)
        {
            string[] splits = value.Split(',');

            if (splits.Length < 2)
                return Vector2.Zero;

            CultureInfo eng = new CultureInfo("en-US");

            Vector2 result = new Vector2();
            result.X = Single.Parse(splits[0], eng);
            result.Y = Single.Parse(splits[1], eng);

            return result;
        }

        public override string ConvertTo(Vector2 value)
        {
            return value.X + "," + value.Y;
        }
    }
}